﻿using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class OrdersDAL : PageDAL<OrdersModel>
    {
        public OrdersModel GetModelByID(string TableName, int id)
        {
            string sql = $"select * from  {TableName} where id='{id}'";
            DataTable dt = new DBHelper().GetDataTable(sql);
            OrdersModel model = new OrdersModel()
            {
                ID = int.Parse(dt.Rows[0]["id"].ToString()),
                Time = DateTime.Parse(dt.Rows[0]["Time"].ToString()),
                Price = decimal.Parse(dt.Rows[0]["price"].ToString()),
                EmployeeID = int.Parse(dt.Rows[0]["EmployeeID"].ToString()),
                VendorID = int.Parse(dt.Rows[0]["VendorID"].ToString()),
                AB = int.Parse(dt.Rows[0]["AB"].ToString()),
                Remark = dt.Rows[0]["Remark"].ToString()
            };
            return model;
        }
        public bool Sh(int a, int pid)
        {
            string sql = $"update Orders set AB={a} where id={pid}";
            return new DBHelper().Zsg(sql);
        }

        public object SelectName(string tableName, string mz)
        {
            string sql = $"select * from {tableName} where EmployeeName like '%{mz}%'";
            return new DBHelper().GetDataTable(sql);
        }
        public DataTable A()
        {
            string sql = "select * from Orders where id = (select max(id) from Orders)";
            return new DBHelper().GetDataTable(sql);
        }
    }
}
